package convert

import (
	"context"
	"github.com/jinzhu/copier"

	"gitee.com/zy_blue7/db-convert-api/internal/svc"
	"gitee.com/zy_blue7/db-convert-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type SaveLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewSaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveLogic {
	return &SaveLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *SaveLogic) Save(req *types.DataConView) (resp *types.BooleanResp, err error) {
	// todo: add your logic here and delete this line
	var config svc.DataConConfig
	err = copier.Copy(&config, req)
	l.svcCtx.DataConConfigs = append(l.svcCtx.DataConConfigs, config)

	return &types.BooleanResp{
		Result: types.Result{
			Code:      200,
			Message:   "",
			ExtInfo:   "",
			Timestamp: 0,
		},
		Data: true,
	}, err
}
